﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Castle.MonoRail.Framework;
using MonoRailDemo.Models;

namespace MonoRailDemo.Controllers
{
    public class PollController : SmartDispatcherController
    {
        private IPollRepository _polls = new XmlPollRepository();

        public void Index()
        {
            PropertyBag["polls"] = _polls.GetAllPolls();
        }

        public void ViewPoll(string id)
        {
            PropertyBag["poll"] = _polls.GetPoll(int.Parse(id));
        }

        public void NewPoll()
        {

        }

        public void AddPoll(string question, string answers)
        {
            _polls.Add(question, answers.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries));
            Redirect("poll", "index");
        }
    }
}
